//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<CBinaryData.cpp>
///	@path	~/src/database/xdata/
///	@date	2007/11/26
///	@desc	Binary data entry.

#include "config/config.h"

#include "object/IBuffer.h"

#include "database/xdata/CBinaryData.h"

namespace xeres {

	IMPL_IOBJECT_CLASS( CBinaryData );

	// CBinaryData
	CBinaryData::CBinaryData( RefWeak<IBuffer> buffer , const WString& name )
		: m_buffer( buffer )
		, m_key( Key::MakeKey( name ) )
	{
	}

	// ~CBinaryData
	CBinaryData::~CBinaryData( void )
	{
	}

	// GetVarTypeName
	const WString& CBinaryData::GetVarTypeName( void ) const
	{
		if( m_buffer.IsValid() )
			return m_buffer->GetClassName();
		static const WString s_VoidTypeName( VOID_TYPE_CLASS_NAME );
		return s_VoidTypeName;
	}

	// GetVarTypeID
	const ClassID CBinaryData::GetVarTypeID( void ) const
	{
		if( m_buffer.IsValid() )
			return m_buffer->GetClassID();
		return VOID_TYPE_CLASS_ID;
	}

	// GetInfo
	bool CBinaryData::GetInfo( DataInfo& datainfo )
	{
		datainfo.m_type = DATA_BIN;
		datainfo.m_size = m_buffer.IsValid() ? m_buffer->GetSize() : 0;
		datainfo.m_created = 0;
		datainfo.m_accessed = 0;
		datainfo.m_modified = 0;
		return true;
	}

	// SetObject
	bool CBinaryData::SetObject( RefWeak<IObject> val )
	{
		if( val.IsValid() && !val->IsA<IBuffer>() )
		{
			return false;
		}
		m_buffer = val;
		return true;
	}

	// GetObject
	bool CBinaryData::GetObject( Ref<IObject>& val ) const
	{
		val = m_buffer;
		return true;
	}

	// Save
	bool CBinaryData::Save( void )
	{
		return false;
	}

	// Reload
	bool CBinaryData::Reload( void )
	{
		return false;
	}

} // namespace xeres
